﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Dangnhap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Browser.Cookies)//
            {
                if (Request.Cookies["user"] != null && Request.Cookies["pass"] != null)
                {
                    HttpCookie cookie_user = new HttpCookie("user");
                    Response.Cookies.Add(cookie_user);// luu cookie vao may cua user
                    Txtusername.Text = Request.Cookies["user"].Value;// lay cookies da ton tai gan vao txtuser
                    //
                    HttpCookie cookie_pass = new HttpCookie("pass");
                    Response.Cookies.Add(cookie_pass);// luu cookie vao may cua pass
                    Txtpassword.Text = Request.Cookies["pass"].Value;// lay cookies da ton tai gan vao txtpass
                }
            }
        }
    }
    private void Checklogin()
    {
        string strCn = System.Configuration.ConfigurationManager.ConnectionStrings["VietComBankConnectionString"].ConnectionString.ToString();
        string strSql = "Select * from Dangnhap";
        SqlConnection Cn = new SqlConnection(strCn);
        SqlDataAdapter da = new SqlDataAdapter(strSql, Cn);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        da.Fill(dt);
        foreach(DataRow dr in dt.Rows)
        {
            if((Txtusername.Text)==dr["username"].ToString() && Txtpassword.Text== dr["password"].ToString())
            {
                
                Session["Login"]=true;
                Response.Redirect("ATM.aspx", false);
                    return;
            }
        }
        tbloi.Text="</br><font color=red>Invalid Account</font>";


    }

    protected void Btlogin_Click(object sender, EventArgs e)
    {
        Checklogin();
    }
}